package com.space.school.services.impl;

import com.space.school.dao.LoginDao;
import com.space.school.dao.RegisterDao;
import com.space.school.dao.impl.LoginDaoImpl;
import com.space.school.dao.impl.RegisterDaoImpl;
import com.space.school.domain.User;
import com.space.school.services.LoginService;
import com.space.school.services.RegisterService;

import java.util.regex.Pattern;

public class RegisterServiceImpl implements RegisterService {
    private RegisterDao registerDao = new RegisterDaoImpl();
    @Override
    public boolean register(String username, String password) {
//        登录校验 通过dao 访问数据库后将值进行返回,
//        看是否有值,有值则登录成功
        //调用登录方法
        int resule= registerDao.register(username, password);
        if (resule>0) {
            return true;
        }
        return false;
    }

    @Override
    public boolean Isregister(String username) {
        User user = registerDao.Isregister(username);
        if (user != null) {
            return true;
        }
        return false;
    }

    @Override
    public boolean difficultyPassword(String password) {
        String regex = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d).{6}$";
        return Pattern.matches(regex, password);
    }
}
